//Flies down and aims holed walls

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let SEshotm1=("script\SoundEffects\shotm1.wav");
let SEshotb6=("script\SoundEffects\shotb6.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=6;
let scale=0.75;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let type=GetArgument;
let direction=rand_int(0,1);
let color=255;

SetAngle(90);
SetSpeed(6);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Ghosts.png");
	LoadSE("script\SoundEffects\shotm1.wav");
	LoadSE("script\SoundEffects\shotb6.wav");

	SetInvincibility(30);
	SetLife(15);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
if(type==1){
	if(time%50==0 && time>=60){
	let angle=GetAngleToPlayer;
	let shot1=0;
	SetShotColor(color,color,color);
		loop(12){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,angle,1,-0.1,2.5,1);
		SetShotDataA(shot1,36,NULL,NULL,0,-0.1,2.5,1);
		FireShot(shot1);
		angle+=360/12;
		}
		loop(12){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,angle,-1,-0.1,2.5,2);
		SetShotDataA(shot1,36,NULL,NULL,0,-0.1,2.5,2);
		FireShot(shot1);
		angle+=360/12;
		}
	color-=20;
	PlaySE(SEshotm1);
	}
} //type 1
if(type==2){
	if(time%50==0 && time>=50){
	let angle=GetAngleToPlayer;
	SetShotColor(color,color,color);
		loop(7){
		CreateShot02(GetX,GetY,5,angle,-0.1,2.6,13,0);
		angle+=360/7;
		}
	color-=20;
	PlaySE(SEshotb6);
	}
} //type 2
SetShotColor(255,255,255);
} //Easy

if(GetCommonData("Difficulty")==2){
if(type==1){
	if(time%40==0 && time>=60){
	let angle=GetAngleToPlayer;
	let shot1=0;
	SetShotColor(color,color,color);
		loop(15){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4.5,angle,1,-0.1,3,1);
		SetShotDataA(shot1,28,NULL,NULL,0,-0.1,3,1);
		FireShot(shot1);
		angle+=360/15;
		}
		loop(15){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4.5,angle,-1,-0.1,3,2);
		SetShotDataA(shot1,28,NULL,NULL,0,-0.1,3,2);
		FireShot(shot1);
		angle+=360/15;
		}
	color-=20;
	PlaySE(SEshotm1);
	}
} //type 1
if(type==2){
	if(time%45==0 && time>=50){
	let angle=GetAngleToPlayer;
	SetShotColor(color,color,color);
		loop(12){
		CreateShot02(GetX,GetY,5,angle,-0.1,3,13,0);
		angle+=360/12;
		}
	color-=20;
	PlaySE(SEshotb6);
	}
} //type 2
SetShotColor(255,255,255);
} //Normal

if(GetCommonData("Difficulty")==3){
if(type==1){
	if(time%25==0 && time>=60){
	let angle=GetAngleToPlayer;
	let shot1=0;
	SetShotColor(color,color,color);
		loop(18){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,5,angle,1,-0.1,3.5,1);
		SetShotDataA(shot1,24,NULL,NULL,0,-0.1,3.5,1);
		FireShot(shot1);
		angle+=360/18;
		}
		loop(18){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,5,angle,-1,-0.1,3.5,2);
		SetShotDataA(shot1,24,NULL,NULL,0,-0.1,3.5,2);
		FireShot(shot1);
		angle+=360/18;
		}
	color-=15;
	PlaySE(SEshotm1);
	}
} //type 1
if(type==2){
	if(time%40==0 && time>=50){
	let angle=GetAngleToPlayer+rand(-3,3);
	SetShotColor(color,color,color);
		loop(16){
		CreateShot02(GetX,GetY,5,angle,-0.1,3,13,0);
		angle+=360/16;
		}
	color-=20;
	PlaySE(SEshotb6);
	}
} //type 2
SetShotColor(255,255,255);
} //Hard

if(GetCommonData("Difficulty")==4){
if(type==1){
	if(time%15==0 && time>=60){
	let angle=GetAngleToPlayer;
	let shot1=0;
	SetShotColor(color,color,color);
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,6,angle,1,-0.1,4,1);
		SetShotDataA(shot1,22,NULL,NULL,0,-0.1,4,1);
		FireShot(shot1);
		angle+=360/20;
		}
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,6,angle,-1,-0.1,4,2);
		SetShotDataA(shot1,22,NULL,NULL,0,-0.1,4,2);
		FireShot(shot1);
		angle+=360/20;
		}
	color-=15;
	PlaySE(SEshotm1);
	}
} //type 1
if(type==2){
	if(time%35==0 && time>=50){
	let angle=GetAngleToPlayer+rand(-5,5);
	SetShotColor(color,color,color);
		loop(18){
		CreateShot02(GetX,GetY,5,angle,-0.1,3,13,0);
		angle+=360/18;
		}
	color-=20;
	PlaySE(SEshotb6);
	}
} //type 2
SetShotColor(255,255,255);
} //Lunatic
} //Onscreen


if(GetSpeed>-0.3 && time<90){ SetSpeed(GetSpeed-0.1); }
if(time>=90){
	SetSpeed(GetSpeed-0.06);
	if(direction==0){ SetAngle(GetAngle+1); }
	if(direction==1){ SetAngle(GetAngle-1); }
}


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
	SetTexture(GRenemy);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	SetGraphicRect(160,211,207,274);
		if(oldX<GetX || oldX>GetX){ SetGraphicRect(208,211,255,274); }
		if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	DrawGraphic(GetX,GetY+5*sin(time*2));
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);
	loop(3){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}